
const ITERATIONS = Number(process.env.ITERATIONS || process.argv[2] || 50000000);

function heavyComputation(iterations) {
    let accumulator = 0;
    for (let i = 0; i < iterations; i++) {
        accumulator += (i ^ (i >>> 3)) % 97;
    }
    return accumulator;
}

const startNs = process.hrtime.bigint();
const result = heavyComputation(ITERATIONS);
const endNs = process.hrtime.bigint();

const durationMs = Number(endNs - startNs) / 1e6;

console.log("Iterations: %d", ITERATIONS);
console.log("Result (ignore, prevents optimization): %d", result);
console.log("Elapsed: %d ms", Math.round(durationMs));